/*
* Copyright (C) 2024-2025 Uniontech Technology Co., Ltd.
*
* Author:      zhangbingyi <zhangbingyia@uniontech.com>
*
* Maintainer:  zhangbingyi <zhangbingyia@uniontech.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PTTABLEMODEL_H
#define PTTABLEMODEL_H
#include "tppolicyinfo.h"

#include <QObject>
#include <QStandardItemModel>

class DBusInvokerInterface;
class Coroutine;
class TPTableModel : public QStandardItemModel
{
    Q_OBJECT
public:
    explicit TPTableModel(QObject *parent = nullptr);
    ~TPTableModel() override;

public:
    void initData();
    void initConnection();

    void getPolicyList(Coroutine* co);

    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;

    virtual bool removeRows(int, int, const QModelIndex &parent = QModelIndex()) override;

    // 向dbus服务插入
    void insertPolicy(const QString &);

public Q_SLOTS:
    void onSyncObject(const QString &, const QString &);
    // 处理IMA监控文件被删除时的事件
    void onIMAComponentRemoved(const QString &);

Q_SIGNALS:
    // 通知界面插入了数据，为其创建下拉框
    void NoticeRowInserted();
    void NoticeModelInitFinished();

private:
    // 向modle中插入一条策略
    void insertPolicy(const TPPolicyInfo &);

private:
    DBusInvokerInterface *m_IMAInvoker;
    DBusInvokerInterface *m_monitorInvoker;
    QMap<int, QString> m_comboIconMap;
    QThread *m_initThread;
    bool m_isRequestStop;
};

#endif // PTTABLEMODEL_H
